package com.woniuxy.controller;

import com.woniuxy.entity.ComComment;
import com.woniuxy.entity.ComCommentLikes;
import com.woniuxy.service.ComCommentService;
import com.woniuxy.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comComment")
public class ComCommentController {

    @Autowired
    private ComCommentService comCommentService;
    //获取指定社区的所有评论
    @RequestMapping("/getCommentsByCommunityId")
    public ResponseResult getCommentsByCommunityId(@RequestParam("comId") Integer comId){
        List<ComComment> commentsList = comCommentService.getCommentsByCommunityId(comId);

        return ResponseResult.success(commentsList);
    }
    //获取热门评论  一定数量的热门评论
    @RequestMapping("/getHotComments")
    public ResponseResult getHotComments(){
        List<ComComment> comments = comCommentService.getHotComments();
        return ResponseResult.success(comments);
    }

    //插入新评论
    @PostMapping("/insertComment")
    public ResponseResult insertComment(@RequestBody ComComment comment){
        comCommentService.insertComment(comment);
        return ResponseResult.success();
    };




    //对指定评论的点赞数进行原子性递增（+1）。
    @RequestMapping("/incrementLikesCount")
    public ResponseResult incrementLikesCount(@RequestParam("userId") Integer userId,@RequestParam("commentId") Integer commentId){
        System.out.println("userId: "+userId+" commentId: "+commentId);
        comCommentService.incrementLikesCount(userId, commentId);
        return ResponseResult.success();
    };

    //对指定评论的点赞数进行原子性递增（-1）。
    @RequestMapping("/decrementLikesCount")
    public ResponseResult decrementLikesCount(@RequestParam("userId") Integer userId, @RequestParam("commentId") Integer commentId){
        comCommentService.decrementLikesCount(userId, commentId);
        return ResponseResult.success();
    };

    /**
     * 获取用户点赞的评论列表
     * @return
     */
    @RequestMapping("getUserLikeComment")
    public ResponseResult getUserLikeComment(@RequestParam("userId") Integer userId){
        List<ComCommentLikes> comCommentLikesList = comCommentService.getUserLikeComment(userId);
        return ResponseResult.success(comCommentLikesList);
    }
}
